﻿#include "AddSceneCmd.h"
#include "../util/JsonUtil.h"
#include "../util/DateTime.h"
#include "../util/HttpUtil.h"
#include "../util/FileUtil.h"
#include "../util/SystemHelper.h"
#include "../util/TextUtil.h"

AddSceneCmd::AddSceneCmd()
{
}

AddSceneCmd::~AddSceneCmd()
{
}

bool AddSceneCmd::Parse(std::string json)
{
	if (!BaseCmd::Parse(json))
	{
		return false;
	}

	// 解析json
	JsonUtil jsonUtil;
	if (jsonUtil.Parse(json))
	{
		std::string id = jsonUtil.GetString("scene.id", "");
		std::string deviceId = jsonUtil.GetString("scene.deviceId", "");
		std::string detectType = jsonUtil.GetString("scene.detectType", "");
		std::string threshold = jsonUtil.GetString("scene.threshold", "80");
		std::string alarmInfo = jsonUtil.GetString("scene.alarmInfo", "");
		std::string alarmCode = jsonUtil.GetString("scene.alarmCode", "");
		std::string createTime = jsonUtil.GetString("scene.createTime", "");
		std::string updateTime = jsonUtil.GetString("scene.updateTime", "");

		m_scene.SetId(id);
		m_scene.SetDevice(deviceId);
		m_scene.SetDetectType(detectType);
		m_scene.SetThreshold(std::stoi(threshold));
		m_scene.SetAlarmInfo(alarmInfo);
		m_scene.SetAlarmCode(alarmCode);

		DateTime time = DateTime::Now();
		time.From(createTime);
		m_scene.SetCreateTime(time);
		time.From(updateTime);
		m_scene.SetUpdateTime(time);

		if (!jsonUtil.HasNode("scene.model"))
		{
			return true;
		}

		std::string mid = jsonUtil.GetString("scene.model.id", "");
		m_scene.SetModel(mid);
		return true;
	}
	return false;
}

SceneInfo AddSceneCmd::GetScene()
{
	return m_scene;
}